// PropertyCustomVisitor.cpp: implementation of the PropertyCustomVisitor class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "PropertyCustomVisitor.h"
#include "PropertyComboWindow.h"
#include "PropertyTextWindow.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
namespace pa
{
	PropertyCustomVisitor::PropertyCustomVisitor()
	{

	}

	PropertyCustomVisitor::~PropertyCustomVisitor()
	{

	}

	BOOL PropertyCustomVisitor::Visit(CustomDBVariable* pVar)
	{
		if(pVar->IsComboBox())
		{
			PropertyComboWindow* pCom = new PropertyComboWindow;
			pCom->customVariable(pVar);
			AddSubWindow(pCom);
		}
		else
		{
			PropertyTextWindow* pText = new PropertyTextWindow;
			pText->customVariable(pVar);
			AddSubWindow(pText);
		}
		return TRUE;
	}
	
	BOOL PropertyCustomVisitor::Visit(CustomNonDBVariable* pVar)
	{
		if(pVar->IsComboBox())
		{			
		}
		else
		{
			PropertyTextWindow* pText = new PropertyTextWindow;
			pText->customVariable(pVar);
			AddSubWindow(pText);
		}
		return TRUE;
	}
		
	BOOL PropertyCustomVisitor::Visit(DBVariable* pVar)
	{
		return TRUE;
	}
		
	BOOL PropertyCustomVisitor::Visit(NonDBVariable* pVar)
	{
		return TRUE;
	}
		
	void PropertyCustomVisitor::AddSubWindow(PropertySubWindow* pSubWin)
	{
		ASSERT(pSubWin != NULL);
		PropertySubWindow* pTemp = NULL;
		for(int i = 0; i<m_theSubWindow.GetSize(); i++)
		{
			pTemp = m_theSubWindow.GetAt(i);
			ASSERT(pTemp != NULL);
			if(pSubWin->customVariable()->ArrangePrior() < pTemp->customVariable()->ArrangePrior())
			{
				m_theSubWindow.InsertAt(i,pSubWin);
					return;
			}
			
		}
		m_theSubWindow.Add(pSubWin);
	}

};